package cn.oa.desktop.newlabel.service.impl;

import cn.oa.desktop.newlabel.beans.BasePage;
import cn.oa.desktop.newlabel.beans.NewLabel;
import cn.oa.desktop.newlabel.dao.NewLabelDao;
import cn.oa.desktop.newlabel.service.NewLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NewLabelServiceImpl implements NewLabelService {
    @Autowired
    private NewLabelDao newLabelDao ;

    @Override
    public List<NewLabel> SelectAll() {
        return newLabelDao.SelectAll();
    }

    @Override
    public void newInsert(NewLabel newLabel) {
        newLabelDao.newInsert(newLabel);
    }

    @Override
    public NewLabel SelectUpdate(String id) {
        return newLabelDao.SelectUpdate(id);
    }

    @Override
    public void NewUpdate( NewLabel newLabel) {
        newLabelDao.NewUpdate(newLabel);
    }

    @Override
    public void NewDelete(int id) {
        newLabelDao.newDelete(id);
    }

    @Override
    public BasePage<NewLabel> SelectPage(Integer page) {
        BasePage<NewLabel> newLabelBasePage = new BasePage<NewLabel>();
        Integer count = newLabelDao.SelectCount();
        newLabelBasePage.setPageC(3);//每页显示记录数
        newLabelBasePage.setCount(count);//总记录数
        if (count%newLabelBasePage.getPageC()==0){
            newLabelBasePage.setPageCount(count/newLabelBasePage.getPageC());
        }else{
            newLabelBasePage.setPageCount(count/newLabelBasePage.getPageC()+1);//总页数
        }
        newLabelBasePage.setPage(page);
        Map<String,Integer> map = new HashMap<String, Integer>();
        map.put("start",(page-1)*newLabelBasePage.getPageC());
        map.put("size",newLabelBasePage.getPageC());
        newLabelBasePage.setNewLabelss(newLabelDao.SelectPage(map));

        return newLabelBasePage;
    }

    @Override
    public NewLabel SelectName(String name) {
        return newLabelDao.SelectName(name);
    }

}
